﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Chowpoo.Sql;

namespace CourseSystem.Core.Entities
{
    [Table(Name = "Section")]
    public class SectionInfo : IDetach
    {
        public SectionInfo()
        {
            Detach();
        }
        #region Model
        private int _id;
        private string _name;
        private int _contentid;
        private int _chapterid = 0;
        private byte _orderid = 0;


        private EntityRef<CommonContentInfo> _commonContentInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_commonContentInfo", ThisKey = "ContentId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public CommonContentInfo CommonContentInfo
        {
            get { return _commonContentInfo.Entity; }
            set { _commonContentInfo.Entity = value; }
        }

        private EntityRef<ChapterInfo> _chapterInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_chapterInfo", ThisKey = "ChapterId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public ChapterInfo ChapterInfo
        {
            get { return _chapterInfo.Entity; }
            set { _chapterInfo.Entity = value; }
        }


        private EntitySet<CourseStudyInfo> _courseStudyInfo;
        [System.Data.Linq.Mapping.Association(Storage = "_courseStudyInfo", ThisKey = "Id", OtherKey = "SectionId")]
        public EntitySet<CourseStudyInfo> CourseStudyInfo
        {
            get { return this._courseStudyInfo; }
            set { this._courseStudyInfo.Assign(value); }
        }

        /// <summary>
        /// 
        /// </summary>
        [Column(IsDbGenerated = true, IsPrimaryKey = true, IsVersion = true)]
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("节名")]
        [Required(ErrorMessage = "必须填写")]
        public string Name
        {
            set { _name = value; }
            get { return _name; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int ContentId
        {
            set { _contentid = value; }
            get { return _contentid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int ChapterId
        {
            set { _chapterid = value; }
            get { return _chapterid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("节数")]
        [RangeValidation(ErrorMessage = "节数无效", Max = 255, Min = 0)]
        public byte OrderId
        {
            set { _orderid = value; }
            get { return _orderid; }
        }
        #endregion Model

        public void Detach()
        {
            this._commonContentInfo = default(EntityRef<CommonContentInfo>);
            this._courseStudyInfo = new EntitySet<CourseStudyInfo>();
            this._chapterInfo = default(EntityRef<ChapterInfo>);
        }
    }
}
